import Vue from 'vue'
import App from '@/App.vue'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import config from '@/config';
import store from '@/store';
require("@/mock")

import http from '@/utils/httpUtils';

Vue.prototype.$http = http('security')

Vue.use(ElementUI, { size: 'mini' });

router.beforeEach((to, from, next) => {
    // 获取本地存储的token
    store.state.token = sessionStorage.getItem('token');
    // 判断该路由是否需要登录权限
    if (to.meta.ignoreAuth) {
        next();
    } else {
        // 通过vuex state获取当前的token是否存储
        if (store.state.token) {
            next();
        } else {
            next({
                path: config.loginUrl,
                // 将跳转的路由path作为参数，登录成功后跳转到该路由
                // query: {redirect: to.fullPath}
            });
        }
    }
})

new Vue({
    router,
    ...App,
    watch: {
        '$route'(to, from) {
        }
    }
}).$mount('#app')